#ifndef __SYSTEM_H
#define __SYSTEM_H
#include "gpio.h"
#include "uart.h"
#include "time.h"
#include "lcd.h"
#include "Bluetooth.h"
void SystemClock_Config(void);

#define	ERR_FAIL		  1
#define	ERR_SUCCESS		  0	
typedef struct
{
	uint16 	aVal;
	uint16	bVal;
	uint16 	cVal;
	uint16 	rVal;�����
} CollectCurData;

typedef struct
{
	uint16 	aVal;
	uint16	bVal;
	uint16 	cVal;
} CollectVolData;

typedef struct
{
	uint16 	aVal;
	uint16	bVal;
	uint16 	cVal;
	uint16 	sVal;���

} CollectTemData;

/**************************
	��������ֵ
**************************/
#define   Over_VoltageValue				242 
#define   Under_VoltageValue			182
#define   Over_CurrentValue				10000 
#define   Over_ResidualsCurrentValue	1000 
#define   Over_TemperatureValue			700 ���϶�


#define		ResidualsCurrent_Zero_Point		100��⵽ʣ�����С�ڴ�ֵ˵������Ϊ0

#define 	IMEI_Len 		15
#define		DEVEUI_Len		16
typedef enum 
{
	NotDetectModule=0,
    LoraModule = 1,
    NBModule=2,
}BoardModuleType;

typedef struct
{
	CollectCurData	CurData;
	CollectVolData	VolData;
	CollectTemData	TemData;
	uint8			SignalStrength;
	uint8			OnLineFlag;
	uint8			IMEI[IMEI_Len+1];
	uint8			DEVEUI[DEVEUI_Len+1];

	BoardModuleType	ModuleType;
	

} CollectedData;������ֲ�����ֵ

typedef enum 
{
	CurrentValue=0x01,
	VoltageValue=0x02,
	TemperatureValue=0x03,
	IMEIValue=0x04,
	DEVEUI=0x05,
	ErrorType=0x06,
	ThresholdValue=0x07,
	ChannleEnableValue=0x08

}CollectedDataType;

typedef struct
{
  uint8		CurChannle_a;
  uint8		CurChannle_b;
  uint8		CurChannle_c;
  uint8		CurChannle_r;

  uint8		VolChannle_a;
  uint8		VolChannle_b;
  uint8		VolChannle_c;
  
  uint8		TemChannle_a;
  uint8		TemChannle_b;
  uint8		TemChannle_c;
  uint8		TemChannle_s;

} ChannleEnableStatus;��·����״̬
#define  Channle_Status_Close  0x55
#define  Channle_Status_Open   0xaa



typedef struct
{
  uint8		CurChannle_a_Warn;
  uint8		CurChannle_b_Warn;
  uint8		CurChannle_c_Warn;
  uint8		CurChannle_r_Warn;

  uint8		VolChannle_a_Warn;
  uint8		VolChannle_b_Warn;
  uint8		VolChannle_c_Warn;

  uint8		TemChannle_a_Warn;
  uint8		TemChannle_b_Warn;
  uint8		TemChannle_c_Warn;
  uint8		TemChannle_s_Warn;
  
} ChannleWarnStatus;��·��������״̬
extern		ChannleWarnStatus	WarnStatus;
#define	  Cur_Warn_Normal		1
#define	  Cur_Warn_OverCurrent	2
#define	  Cur_Warn_NoSensor	    9

#define	  Vol_Warn_Normal		3
#define	  Vol_Warn_OverVoltage	4
#define	  Vol_Warn_UnderVoltage	5

#define	  Tem_Warn_Normal	    6
#define	  Tem_Warn_OverHigh		7
#define	  Tem_Warn_NoSensor	    8

#define		Voltage_Zero_Point		50��⵽��ѹС�ڸ�ֵ����Ϊ��û�Ӵ�����


typedef struct
{
  uint8		run_led;
  uint8		alarm_led;
  uint8		malfunction_led;
  uint8		missingPhase_led;
} AllLedStatus;����ת̬
extern	AllLedStatus		LedStatus;
#define  LED_Enable			2
#define  LED_Disable		3




extern	CollectedData	collectData;
extern	uint8 	volatile Debug_Send_Data_Flag;
extern	uint16 	volatile Debug_Send_Data_Value;
extern	uint8 	volatile Debug_Send_Data_Cnt;
extern	CollectedData     	ReceData;

#define FW_VERSION  "SwV1.1-20200528"


typedef struct
{
  uint8		Menu_Key_ShortPress;
  uint8		Menu_Key_LongPress;
  uint16    Menu_Key_Low_Time;
  uint8		Move_Key_Press;
  uint16    Move_Key_Low_Time;
  uint8		Select_Key_Press;
  uint16    Select_Key_Low_Time;
  uint8		Key_Int;
  uint8		BuzzerFlag;
} KeyStatus;����״̬
extern	KeyStatus			KeyStatu;



typedef enum 
{
  Menu_Inital=1,
  Menu_ShowData=2,
  Menu_EnterSet=3, 
  Menu_ShowSysInfor=4
}MenuStatus;





typedef struct
{
	����
	uint16 	TemThreshold_a;		���¶����ޣ���λ���϶�
	uint16 	TemThreshold_b;
	uint16 	TemThreshold_c;
	uint16 	TemThreshold_s;		����¶����ޣ���λ���϶�
	
	uint16 	Vol_OverThreshold_a; ���ѹ���ޣ���λV
	uint16 	Vol_BelowThreshold_a;��Ƿѹ���ޣ���λV
	uint16 	Vol_OverThreshold_b; ���ѹ���ޣ���λV
	uint16 	Vol_BelowThreshold_b;��Ƿѹ���ޣ���λV
	uint16 	Vol_OverThreshold_c; ���ѹ���ޣ���λV
	uint16 	Vol_BelowThreshold_c;��Ƿѹ���ޣ���λV

	uint16 	CurThreshold_a;		��������ޣ���λA
	uint16 	CurThreshold_b;
	uint16 	CurThreshold_c;
	uint16 	CurThreshold_r;		��������ޣ���λA
	uint16 	PowerThreshold;	�ܹ������ޣ���λW
} ThresholdVal;

/*****
SetThresholdValue
Date:20200316163701		����
TemThreshold_a:40		���¶����ޣ���λ���϶�
TemThreshold_b:40
TemThreshold_c:40
TemThreshold_s:50		����¶����ޣ���λ���϶�

Vol_OverThreshold_a:240
Vol_BelowThreshold_a:200
Vol_OverThreshold_b:240
Vol_BelowThreshold_b:200
Vol_OverThreshold_c:240
Vol_BelowThreshold_c:200

CurThreshold_a:100		��������ޣ���λA
CurThreshold_b:100
CurThreshold_c:100
CurThreshold_s:1.5			��������ޣ���λA
PowerThreshold:80000 	�ܹ������ޣ���λW
OK                                   ��OK��β
****/
#define InterFlashAddress		(0x8000000+1024*63)
#define	Not_UsedDefaultValue	0xAA	

typedef struct
{
	uint8			thresholdVal_UsedDefault;
	ThresholdVal	thresholdVal;
	uint8			ChannleStatus_UsedDefault;
	ChannleEnableStatus	ChannleStatus;
	uint8			sendAlarmInforFlag;
} Sys_Para;����״̬
extern	Sys_Para			SysPara;


#define		Cmd1Header           	 "SetThredValue"
#define		Cmd1SuccessAck           "SetThredValueSuccess"

#define		Cmd2SendDataToServer     "SendDataToServer"
#define		Cmd2SuccessAck           "IWillSendDataToServer"


#define		Cmd3Header           	 "SetChannleEnableVal"
#define		Cmd3SuccessAck           "SetChannleEnableValSuccess"

#define		Cmd4Header           	 "SetThresholdValue"
#define		Cmd4SuccessAck           "SetThresholdValueSuccess"

#define		Cmd5Header           	 "SetChannleEnable"
#define		Cmd5SuccessAck           "SetChannleEnableSuccess"


uint8 UtilFindStringContent(const uint8* str,uint8 slen, const uint8* des);

#define		Version           	 "1.0-20200702"

#endif
